package com.mikepenz.presenter.imp;

import android.app.Activity;
import android.content.Context;

import com.android.volley.VolleyError;
import com.mikepenz.app.R;
import com.mikepenz.bean.OrderBean;
import com.mikepenz.interactor.OrderInteractor;
import com.mikepenz.interactor.imp.OrderInteractorImp;
import com.mikepenz.presenter.listener.RequestListener;
import com.mikepenz.utils.CookicUntil;
import com.mikepenz.utils.MethodType;
import com.mikepenz.view.OrderDetailView;

/**
 * Created by lilongfei on 15/10/4.
 */
public class OrderPresenterImp implements RequestListener<OrderBean> {

    Context c;
    OrderDetailView view;
    OrderInteractor interactor;

    public OrderPresenterImp(Context c) {
        this(c, (OrderDetailView) c);
    }

    public OrderPresenterImp(Context c, OrderDetailView view) {
        this.c = c;
        this.view = view;
        this.interactor = new OrderInteractorImp(c, this);
    }



    public void getOrder(){
        view.showLoad();
        OrderBean order = (OrderBean) ((Activity) c).getIntent().getExtras().getSerializable(CookicUntil.ORDER);
        String userId = CookicUntil.getUser().getUserId();
        interactor.getOrder(userId,order.getOrderCode());
    }

    @Override
    public void Success(String tag, OrderBean result) {
        if (tag.equals(MethodType.ORDER_DETAIL)) {
            if (result == null) {
                view.showError("未获取到订单数据");
                return;
            } else {
                view.refreshView(result);
            }
        }

        view.dismissLoad();
    }

    @Override
    public void Error(String tag, String error) {
        view.dismissLoad();
        view.showError(error);
    }

    @Override
    public void Exception(String tag, VolleyError error) {
        view.dismissLoad();
        view.showError(c.getString(R.string.system_error));
    }


}
